package com.xiaobaibai.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraint implements ConstraintValidator<ListValue, Integer> {

    private Set<Integer> set=new HashSet<>();

    //初始化
    @Override
    public void initialize(ListValue constraintAnnotation) {
        //初始化校验器,获取注解里定义的信息
        for (int value : constraintAnnotation.values()) {
            set.add(value);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(integer);
    }

}
